' ****** START INCLUDE Polygon Macro Support ******
DIM AS INTEGER StartX, StartY, PreviousX, PreviousY, LeftMostX, LeftMostY, LeftMostNear1X, LeftMostNear1Y, LeftMostNear2X, LeftMostNear2Y, LeftMostBuddyX, LetMostBuddyY

SUB DoPostLine()
    IF POINT(0) < LeftMostX THEN
      LeftMostX = POINT(0) : LeftMostY = POINT(1) : LeftMostNear1X = PreviousX : LeftMostNear1Y = PreviousY : LeftMostNear2X = -1 : LeftMostNear2Y = -1
    ELSE
      IF LeftMostNear2X = -1 THEN LeftMostNear2X = POINT(0) : LeftMostNear2Y = POINT(1)
    END IF
    PreviousX = POINT(0): PreviousY = POINT(1)
END SUB
'  ****** END INCLUDE Polygon Macro Support ******

TYPE FPP ' Five Point Polygon
  x1 y1 x2 y2 x3 y3 x4 y4 x5 y5
END TYPE

DIM as FPP p1,p2,pj

ws = 400
SCREEN _NEWIMAGE(ws, ws, 12)
movement_steps = 100

DEF FNrp = RND * ws
DEF FNpj(v1,v2) = SGN(v2 - v1) * ABS( v2 - v1 )  / movement_steps

p1.x1 = FNrp : p1.y1 = FNrp
p1.x2 = FNrp : p1.y2 = FNrp
p1.x3 = FNrp : p1.y3 = FNrp
p1.x4 = FNrp : p1.y4 = FNrp
p1.x5 = FNrp : p1.y5 = FNrp

🟡again: 

p2.x1 = FNrp : p2.y1 = FNrp
p2.x2 = FNrp : p2.y2 = FNrp
p2.x3 = FNrp : p2.y3 = FNrp
p2.x4 = FNrp : p2.y4 = FNrp
p2.x5 = FNrp : p2.y5 = FNrp

pj.x1 = FNpj(p1.x1,p2.x1) : pj.y1 = FNpj(p1.y1,p2.y1)
pj.x2 = FNpj(p1.x2,p2.x2) : pj.y2 = FNpj(p1.y2,p2.y2)
pj.x3 = FNpj(p1.x3,p2.x3) : pj.y3 = FNpj(p1.y3,p2.y3)
pj.x4 = FNpj(p1.x4,p2.x4) : pj.y4 = FNpj(p1.y4,p2.y4)
pj.x5 = FNpj(p1.x5,p2.x5) : pj.y5 = FNpj(p1.y5,p2.y5)

FOR i = 1 TO movement_steps

    CLS

    p1.x1 += pj.x1 : p1.y1 += pj.y1
    p1.x2 += pj.x2 : p1.y2 += pj.y2
    p1.x3 += pj.x3 : p1.y3 += pj.y3
    p1.x4 += pj.x4 : p1.y4 += pj.y4
    p1.x5 += pj.x5 : p1.y5 += pj.y5

    PSET (p1.x1,p1.y1)  : StartX = POINT(0) : StartY = POINT(1) : LeftMostX = POINT(0) : LeftMostY = POINT(1) : LeftMostNear1X = -1 : LeftMostNear1Y = -1 : LeftMostNear2X = -1 : LeftMostNear2Y = -1 : PreviousX = POINT(0) : PreviousY = POINT(1)
LINE - (p1.x2,p1.y2),14 : DoPostLine()
LINE - (p1.x3,p1.y3),14 : DoPostLine()
LINE - (p1.x4,p1.y4),14 : DoPostLine()
LINE - (p1.x5,p1.y5),14 : DoPostLine()
IF LeftMostNear1X = -1 THEN LeftMostNear1X = POINT(0) : LeftMostNear1Y = POINT(1) 
 LINE - (StartX, StartY) ,14 : DoPostLine()

IF LeftMostNear1Y < LeftMostNear2Y THEN 

   LeftMostBuddyX = LeftMostNear1X : LeftMostBuddyY = LeftMostNear1Y 

ELSE 

   LeftMostBuddyX = LeftMostNear2X : LeftMostBuddyY = LeftMostNear2Y 

END IF 


    
    CIRCLE (p1.x1,p1.y1),5,16-1
    CIRCLE (p1.x2,p1.y2),5,16-2
    CIRCLE (p1.x3,p1.y3),5,16-3
    CIRCLE (p1.x4,p1.y4),5,16-4
    CIRCLE (p1.x5,p1.y5),5,16-5

    _DELAY 0.01

NEXT i

GOTO 🟡again